package com.example.gesturerecognition.controller;

import com.example.gesturerecognition.model.Response;
import com.example.gesturerecognition.model.User;
import com.example.gesturerecognition.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation("检验用户注册")
    @PostMapping("/register")
    public Response register(User user)
    {
        //获得注册的信息
        String message = userService.register(user);
        if(message.equals(UserService.registerSuccess))
            return new Response(200,message,null);
        else
            return new Response(600, message,null);//600为自定义状态码，表示注册未成功
    }

    @ApiOperation("检验用户登录")
    @PostMapping("/login")
    public Response login(@RequestParam(name="email") String email, @RequestParam(name="password") String password)
    {
        String message = userService.login(email, password);
        if(message.equals(UserService.loginSuccess))
            return new Response(200,message,null);
        else
            return new Response(601,message,null);//601为自定义状态码，表示登录未成功
    }
}
